#include <algorithm>
#include <vector>
using namespace std;
int largestSumAfterKNegations(vector<int> &nums, int k) {
  sort(nums.begin(), nums.end(), [](int a, int b) { return abs(a) > abs(b); });
  for (int i = 0; i < nums.size() && k > 0; ++i) {
    if (nums[i] < 0) {
      nums[i] *= -1;
      k--;
    }
  }
  if (k > 0 && k % 2 == 1) {
    nums[nums.size() - 1] *= -1;
  }
  int sum = 0;
  for (auto i : nums) {
    sum += i;
  }
  return sum;
}